/* Copyright (C) 2005, 2006 by Daniel Gheorghian
 All rights reserved
 
 Use and distribute freely, except: don't remove my name from the source or documentation 
 (don't take credit for my work), mark your changes (don't get me blamed for your possible bugs),
 don't alter or remove this notice.
 
 No warrantee of any kind, express or implied, is included with this software; use at your
 own risk, responsibility for damages (if any) to anyone resulting from the use of this
 software rests entirely with the user.
 
 Send bug reports, bug fixes, enhancements, requests, flames, etc., and I'll try to keep 
 a version up to date.  I can be reached at: daniel.gheorghian@gmail.com
*/


package com.ds.components.bars;

import javax.swing.*;
import java.awt.*;

public class StraightBar extends JPanel
{
	//todo add a renderer mechanism instead of the Paint, for background painting
	private Paint backgoundPaint;
	private int connectorSize;
	private int borderSize;

	public StraightBar()
	{
		super();

		this.connectorSize = 10;
		this.borderSize = 5;

		this.setPreferredSize( new Dimension( connectorSize + 2 * borderSize, 100 ) );
	}

	public void paint( Graphics g )
	{
		int w = this.getWidth();
		int h = this.getHeight();
		this.backgoundPaint = new GradientPaint( w / 2, 0, new Color( 240, 226, 161 ), w / 2, h, new Color( 250, 189, 96 ) );

		Graphics2D g2D = ( Graphics2D ) g;
		g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
		g2D.setPaint( this.getBackground() );
		g2D.fillRect( 0, 0, w, h );

		g2D.setPaint( backgoundPaint );
		g2D.fillRect( borderSize, borderSize, connectorSize, h - 2*borderSize );
//		g2D.fillRect( borderSize, borderSize, w, h );
	}

	public int getConnectorSize()
	{
		return connectorSize;
	}

	public void setConnectorSize( int connectorSize )
	{
		this.connectorSize = connectorSize;
		this.setPreferredSize( new Dimension( connectorSize + 2 * borderSize, this.getHeight() ) );
	}

	public int getBorderSize()
	{
		return borderSize;
	}

	public void setBorderSize( int borderSize )
	{
		this.borderSize = borderSize;
		this.setPreferredSize( new Dimension( connectorSize + 2 * borderSize, this.getHeight() ) );
	}

}
